import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// import Msite from '../pages/Msite/Msite.vue'
// import Order from '../pages/Order/Order.vue'
// import Profile from '../pages/Profile/Profile.vue'
// import Search from '../pages/Search/Search.vue'
// import Login from '@/pages/Login/Login.vue'


// import Shop from '../pages/Shop/Shop'
// import ShopGoods  from '../pages/Shop/ShopGoods/ShopGoods'
// import ShopRatings  from '../pages/Shop/ShopRatings/ShopRatings'
// import ShopInfo  from '../pages/Shop/ShopInfo/ShopInfo'
const router = new VueRouter({
    routes: [
        { path: '/', redirect: '/msite' },  //重定向
        {
            path: '/msite',
            component: () => import('../pages/Msite/Msite.vue'),
            meta: {
                showFooter: true
            }
        },
        {
            path: '/order', component: () => import('../pages/Order/Order.vue'),
            meta: {
                showFooter: true
            }
        },
        {
            path: '/profile', component: () => import('../pages/Profile/Profile.vue'),
            meta: {
                showFooter: true
            }
        },
        {
            path: '/search', component: () => import('../pages/Search/Search.vue'),
            meta: {
                showFooter: true
            }
        },
        { path: '/login', component: () => import('../pages/Login/Login.vue'), },    //meta:{} 默认就有 默认就是空对象 

        {
            path: '/shop', component: () => import('../pages/Shop/Shop'),
            children: [
                {
                    path: '/shop/goods', component: () => import('../pages/Shop/ShopGoods/ShopGoods'),
                },
                {
                    path: '/shop/ratings', component: () => import('../pages/Shop/ShopRatings/ShopRatings'),
                },
                {
                    path: '/shop/info', component: () => import('../pages/Shop/ShopInfo/ShopInfo'),
                },
                {
                    path: '', redirect: '/shop/goods'
                }
            ]

        }
    ]
})






router.beforeEach((to, from, next) => {
    let  userInfoId=window.localStorage.getItem('userInfoId');
    
    console.log(userInfoId)
    if (to.path =='/login') {
        next()

    } else {
        if (userInfoId) {
            next()
        } else {
            next('/login')
        }
    }


})





export default router


